/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Manager;

import GameState.IGameState;
import java.util.Vector;
import javax.media.opengl.GL2;


/**
 *
 * @author trong_000
 */
public class StateManager {
   Vector<IGameState> listState = new Vector();
   private static StateManager instance = null;
   
   public static StateManager getInstance(){
       if(instance==null){
           instance = new StateManager();
       }
       return instance;
   }
   private StateManager(){
       
   }
   
   public void init(){
       listState.lastElement().init();
   }
   
   public void update(long deltaTime){
       listState.lastElement().update(deltaTime);
   }
   
   public void render(GL2 gl){
       listState.lastElement().render(gl);
   }
   
   public void addState(IGameState state){
       listState.addElement(state);
   }
   
   public void removeState(IGameState state){
       listState.remove(state);
   }
   
   public void exitCurrentState(){
       listState.lastElement().exit();
       listState.remove(listState.size()-1);
   }
   
   public void clearAllState(){
       for (int i = 0; i < listState.size(); i++) {
           listState.get(i).exit();
       }
       listState.clear();
   }
   
   public IGameState getPreviousState(){
       return listState.elementAt(listState.size()-2);
   }
}
